#ifndef __COMM_HPP__
#define __COMM_HPP__

#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>




const std::string pathname = "/home/ssy";
const int proj_id = 0x6666;
const int size = 4096;

key_t GetKey()
{
    key_t k = ftok(pathname.c_str(), proj_id);
    if(k < 0)
    {
        std::cout << "ftok fail" << std::endl;
        exit(1);
    }

    return k;
}


int GetShm()
{
    key_t key = GetKey();
    int shmid = shmget(key, size, 0);
    if(shmid == -1)
    {
        std::cout << "shmget fail" << std::endl;
        exit(1);
    }
    return shmid;
}

int CreateShm()
{
    key_t key = GetKey();
    int shmid = shmget(key, size, IPC_CREAT |IPC_EXCL | 0666);
    if(shmid == -1)
    {
        std::cout << "shmget fail" << std::endl;
        exit(1);
    }
    return shmid;
}

#endif